<template>
  <span >
    <el-form-item prop="warehouseId" label="仓库名称">
      <r-select
        v-validate="'required'"
        v-model="search.warehouseId"
        class="search-input"
        placeholder="请选择"
        selectid="WAREHOUSE_ID"
        selectname="WAREHOUSE_NAME"
        url="/basedata/slstore/vehicleWarehouse/checks"
        model="DCSCLOUD_SALES"
      />
    </el-form-item>
    <el-form-item prop="pLocationId" label="库区">
      <r-select
        v-validate="'required'"
        v-model="search.pLocationId"
        :url="pLocationurl"
        :disabled="pLocationIdabled"
        class="search-input"
        selectid="LOCATION_ID"
        selectname="LOCATION_NAME"
        model="DCSCLOUD_SALES"
        @change="pLocationIdChange"
      />
    </el-form-item>
    <el-form-item prop="locationId" label="库位">
      <r-select
        v-validate="'required'"
        v-model="search.locationId"
        :url="locationurl"
        :disabled="locationabled"
        class="search-input"
        selectid="LOCATION_ID"
        selectname="LOCATION_NAME"
        model="DCSCLOUD_SALES"
      />
    </el-form-item>
  </span>
</template>

<script>

import filtercode from '@/components/Checkbox/filtercode'
import BaseTable from '@/components/BaseTable'
import formMixins from '@/mixins/formMixins'
import rSelect from '@/components/Select/Select'
import { queryLocationValidAndNotLock } from '@/api/salesstore/dcs/basedata/location'
export default {
  name: 'BsmDropDown',
  components: {
    BaseTable,
    rSelect,
    filtercode

  },
  mixins: [formMixins],
  props: {
    search: Object

  },
  data() {
    return {
      pLocationIdabled: true,
      locationabled: true
    }
  },

  computed: {
    pLocationurl: function() {
      this.search.pLocationId = ''
      this.search.locationId = ''
      if (this.search.warehouseId === '') {
        this.pLocationIdabled = true
        this.locationabled = true
      } else {
        (
          this.pLocationIdabled = false
        )
      }
      if (this.search.warehouseId !== '') {
        return '/basedata/location/vehicleWarehouse/queryParValid/' + this.search.warehouseId
      } else {
        return ''
      }
    },
    locationurl: function() {
      this.search.locationId = ''
      if (this.search.pLocationId === '') {
        this.locationabled = true
      } else {
        (
          this.locationabled = false
        )
      }
      if (this.search.pLocationId !== '') {
        return '/basedata/location/vehicleWarehouse/queryLocationValidAndNotLock/' + this.search.pLocationId
      } else {
        return ''
      }
    }
  },
  mounted() {
  },
  methods: {
    pLocationIdChange() {
      if (this.search.pLocationId !== '' && this.search.pLocationId !== undefined) {
        queryLocationValidAndNotLock(this.search.pLocationId).then(res => {
          if (res.length > 0) {
            this.search.locationId = res[0].LOCATION_ID
          }
        }).catch(err => {
        })
      }
    }

  }
}
</script>

<style scoped>

.magnifier {
  float: right;
  position: absolute;
  right: 50px;
  top: 23px;
  cursor: pointer;
}
</style>
